package com.wanxi.dangdang.controller.front.order;

import com.github.pagehelper.PageInfo;
import com.wanxi.dangdang.common.CommonResult;
import com.wanxi.dangdang.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Map;

/**
 * @Author: 寇文宝&王康
 * @Description: B端分销商API
 * @Date: Created in 2021/8/30
 * @Version: 1.1
 */

@Api(tags = "分销商订单管理，均需要登录")
@RestController
@RequestMapping("/front/b/order")
public class BOrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("分销商查询订单分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "分销商ID", dataType = "Int", paramType = "query")
    })
    @GetMapping("/findPage")
    public CommonResult findPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            HttpSession session
    ) {
        Long storeId = (Long) session.getAttribute("id");
        PageInfo pageInfo = orderService.findDistributorOrderPage(pageNum, pageSize, storeId);
        return CommonResult.success(pageInfo);
    }

    @ApiOperation("分销商查询订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单ID", dataType = "Long", paramType = "query")
    })
    @GetMapping("/findById")
    public CommonResult findById(Long id, HttpSession session) {
        Long storeId = (Long) session.getAttribute("id");
        Map<String, Object> map = orderService.findBDetailsByOrderId(id, storeId);
        return CommonResult.success(map);
    }

    @ApiOperation("分销商通过出行日期查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(name = "tripDate", value = "出行日期", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "分销商ID", dataType = "Int", paramType = "query")
    })
    @GetMapping("/findByDate")
    public CommonResult findByDate(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            Date tripDate,
//            Long tripDate,
            HttpSession session
    ) {
        Long storeId = (Long) session.getAttribute("id");
        PageInfo pageInfo = orderService.findDistributorOrderByDate(pageNum, pageSize, tripDate, storeId);
        return CommonResult.success(pageInfo);
    }

}
